﻿using SubRepair.ChangeEncoding;
using SubRepair.SubRepairSetting;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace SubRepair
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ConvertToUTF8 Convertor;
        public ObservableCollection<string> Files
        {
            get
            {
                return files;
            }
        }
        private ObservableCollection<string> files = new ObservableCollection<string>();

        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = this;
            this.Convertor = new Convert1256ToUTF8();
        }

        private void ListBoxDragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effects = DragDropEffects.Copy;
                var listbox = sender as ListBox;
                listbox.Background = new SolidColorBrush(Color.FromArgb(255, 200, 200, 200));
            }
            else
            {
                e.Effects = DragDropEffects.None;
            }
        }

        private void ListBoxDragLeave(object sender, DragEventArgs e)
        {
            var listbox = sender as ListBox;
            listbox.Background = new SolidColorBrush(Color.FromArgb(128, 212, 216, 212));
        }

        private void ListBoxDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] _files = (string[])e.Data.GetData(DataFormats.FileDrop);

                foreach (string filePath in _files)
                {
                    if (SubRepairSetting.SubSettings.IsFileValid(filePath))
                    {
                        files.Add(filePath);
                        this.Convertor.Set(filePath);
                        this.Convertor.Convert();
                    }
                }
            }

            var listbox = sender as ListBox;
            listbox.Background = new SolidColorBrush(Color.FromArgb(128, 212, 216, 212));
        }

        private void AboutClick(object sender, RoutedEventArgs e)
        {
            About about = new About();
            about.Owner = this;
            about.ShowDialog();
        }

    }
}
